unit FormEditContractor;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxMemo, cxLabel, cxControls, cxContainer, cxEdit, cxTextEdit,
  StdCtrls, ExtCtrls,DataModule, DB, ADODB;

type
  TfrmEditContractor = class(TForm)
    qContractor: TADOQuery;
    Panel1: TPanel;
    cxeFax: TcxTextEdit;
    cxLabel8: TcxLabel;
    cxeWWW: TcxTextEdit;
    cxLabel6: TcxLabel;
    cxeEmail: TcxTextEdit;
    cxLabel9: TcxLabel;
    cxLabel1: TcxLabel;
    cxLabel7: TcxLabel;
    cxLabel4: TcxLabel;
    cxeTitle: TcxTextEdit;
    cxeContactPerson: TcxTextEdit;
    cxeInn: TcxTextEdit;
    cxLabel2: TcxLabel;
    cxLabel3: TcxLabel;
    cxLabel5: TcxLabel;
    cxePostAddress: TcxTextEdit;
    cxeLegalAddress: TcxTextEdit;
    cxePhone: TcxTextEdit;
    Panel2: TPanel;
    btnDone: TButton;
    btnClose: TButton;
    procedure btnDoneClick(Sender: TObject);
    procedure btnCloseClick(Sender: TObject);
  private
    fIdContractor : integer;
  public
    constructor Create(Sender: TComponent; aContractorId: integer); reintroduce;
  end;

var
  frmEditContractor: TfrmEditContractor;

implementation

{$R *.dfm}
constructor TfrmEditContractor.Create(Sender: TComponent; aContractorId: integer);
begin
    inherited Create(Sender);
    if aContractorId > 0  then begin
        qContractor.Parameters.ParamByName('pIdContractor').Value := aContractorId;
        qContractor.Open;

        cxeEmail.Text         := qContractor.FieldByName('email').AsString;
        cxeFax.Text           := qContractor.FieldByName('fax').AsString;
        cxeWWW.Text           := qContractor.FieldByName('www').AsString;
        cxeTitle.Text         := qContractor.FieldByName('title').AsString;
        cxeContactPerson.Text := qContractor.FieldByName('contact_person').AsString;
        cxeInn.Text           := qContractor.FieldByName('inn').AsString;
        cxePostAddress.Text   := qContractor.FieldByName('post_address').AsString;
        cxeLegalAddress.Text  := qContractor.FieldByName('legal_address').AsString;
        cxePhone.Text         := qContractor.FieldByName('phone').AsString;
    end;
    fIdContractor := aContractorId;
end;

procedure TfrmEditContractor.btnDoneClick(Sender: TObject);
begin
    if not qContractor.Active then qContractor.Open;
    if fIdContractor < 0 then
        qContractor.Append
    else
        qContractor.Edit;

    qContractor['email']           := cxeEmail.Text;
    qContractor['fax']             := cxeFax.Text;
    qContractor['www']             := cxeWWW.Text;
    qContractor['title']           := cxeTitle.Text;
    qContractor['contact_person']  := cxeContactPerson.Text;
    qContractor['inn']             := cxeInn.Text;
    qContractor['post_address']    := cxePostAddress.Text;
    qContractor['legal_address']   := cxeLegalAddress.Text;
    qContractor['phone']           := cxePhone.Text;
    qContractor.Post;

    Close;

end;

procedure TfrmEditContractor.btnCloseClick(Sender: TObject);
begin
    Close;
end;

end.
